package cn.pacerx.running.db.typehandler;


import java.sql.CallableStatement;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;

import org.apache.ibatis.type.BaseTypeHandler;
import org.apache.ibatis.type.JdbcType;

import cn.pacerx.running.db.enums.ActivityStatusEnum;

public class ActivityStatusTypeHandler extends BaseTypeHandler<ActivityStatusEnum> {

    @Override
    public void setNonNullParameter(PreparedStatement preparedStatement, int i, ActivityStatusEnum activityStatusEnum,
                                    JdbcType jdbcType) throws SQLException {
        preparedStatement.setInt(i, activityStatusEnum.getValue());
    }

    @Override
    public ActivityStatusEnum getNullableResult(ResultSet resultSet, String s) throws SQLException {
        return ActivityStatusEnum.getByValue(resultSet.getInt(s));
    }

    @Override
    public ActivityStatusEnum getNullableResult(ResultSet resultSet, int i) throws SQLException {
        return ActivityStatusEnum.getByValue(resultSet.getInt(i));
    }

    @Override
    public ActivityStatusEnum getNullableResult(CallableStatement callableStatement, int i) throws SQLException {
        return ActivityStatusEnum.getByValue(callableStatement.getInt(i));
    }
}
